<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="所属站点">
        <el-radio-group v-model="form.site_id" @change="search">
          <el-radio-button :value="0" :label="0">全部</el-radio-button>
          <el-radio-button
            v-for="item in cityList"
            :key="item.site_id"
            :label="item.site_id"
            :value="item.site_id"
          >
            {{ item.region_name }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="所属公司">
        <el-radio-group v-model="form.tenant_id" @change="search">
          <el-radio-button :label="0" :value="0"> 全部 </el-radio-button>
          <el-radio-button
            v-for="item in tenantList"
            :key="item.id"
            :label="item.id"
            :value="item.id"
          >
            {{ item.title }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="状态">
        <el-radio-group v-model="form.type" @change="search">
          <el-radio-button :label="99">全部</el-radio-button>
          <el-radio-button :label="3">保证金</el-radio-button>
          <el-radio-button :label="4">还款</el-radio-button>
          <el-radio-button :label="11">商城</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="姓名">
        <el-input v-model="form.realname" clearable />
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.tel" clearable />
      </el-form-item>
      <br />
      <el-form-item label="开始时间">
        <el-date-picker
          v-model="form.startDate"
          type="date"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          v-model="form.endDate"
          type="date"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { ref } from 'vue';
  import { EleMessage } from 'ele-admin-plus/es';
  import { useFormData } from '@/utils/use-form-data';
  import { getCityList } from '@/api/system/region';
  import { getTenantList } from '@/api/tenant';
  const emit = defineEmits(['search']);
  const props = defineProps({
    where: Object
  });

  /** 站点数据 */
  const cityList = ref([]);
  /** 表单数据 */
  const [form] = useFormData({
    site_id: 0,
    type: 99,
    tenant_id: 0,
    tel: '',
    realname: '',
    endDate: '',
    startDate: ''
  });
  if (props.where) {
    form.startDate = props.where.startDate ?? '';
    form.endDate = props.where.endDate ?? '';
    form.type = props.where.type ?? 99;
  }
  /** 获取站点数据 */
  getCityList({})
    .then((res) => {
      cityList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });
  /** 租户数据 */
  const tenantList = ref([]);

  /** 获取租户数据 */
  getTenantList({})
    .then((res) => {
      tenantList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 搜索 */
  const search = () => {
    console.log(form);
    emit('search', { ...form });
  };
</script>
